package mx.com.switz.initzero.dao.impl;

import java.util.List;

import javax.sql.DataSource;

import mx.com.switz.initzero.dao.UsuarioDao;
import mx.com.switz.initzero.dto.Usuario;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;

@Repository
public class UsuarioDaoImpl extends JdbcDaoSupport implements UsuarioDao {
	
	@Autowired
	public UsuarioDaoImpl(DataSource dataSource){
		setDataSource(dataSource);
	}
	

	@Override
	public void insertUsuario(Usuario usuario) {
		// TODO Auto-generated method stub
		SimpleJdbcInsert insert=new SimpleJdbcInsert(getDataSource());
		insert.withTableName("usuario");
		
		SqlParameterSource parameterSource=new BeanPropertySqlParameterSource(usuario);
		insert.execute(parameterSource);
		
		
	}


	@Override
	public List<Usuario> selectAll() {
		// TODO Auto-generated method stub
		return getJdbcTemplate().query("select * from usuario",
				ParameterizedBeanPropertyRowMapper.newInstance(Usuario.class));
	}

}
